#pragma once
#include <iostream>
#include <string>
#include <functional>
#include <unistd.h>
#include "InetAddr.hpp"

class Connection;
class Reactor;
using func_t = std::function<void(Connection*)>;

class Connection
{
public:
    Connection(int fd)
        :_fd(fd)
    {}
    void SetEvents(uint32_t events)
    {
        _events = events;
    }
    int Socket()
    {
        return _fd;
    }
    void Close()
    {
        if(_fd > -1)
            ::close(_fd);
    }
    std::string& inbuffer()
    {
        return _inbuffer;
    }
    std::string& outbuffer()
    {
        return _outbuffer;
    }

private:
    int _fd;
    uint32_t _events;
    InetAddr _addr;

    std::string _inbuffer;
    std::string _outbuffer;

public:
    Reactor* _R;
    func_t _recver;
    func_t _sender;
    func_t _excepter;
};